<?
$category_url = $this->category ? $this->category . '/' : '';

   $zagolovok = array(
        1 => 'легковые автомобили',
        2 => 'мото транспорт',
        3 => 'водный транспорт',
        4 => 'трактора и спецтехника',
        5 => 'прицепы и полуприцепы',
        6 => 'грузовики и TIR',
        7 => 'автобусы и бусики',
        8 => 'автодома'
   );
    $text = 'автомобили';
    $vse = 'Все ';
    if(!empty($this->category_id)){
        $text = $zagolovok[$this->category_id];
        if(3 == $this->category_id || 2 == $this->category_id)$vse='Весь ';
    }
?>

<div class="page-caption">
    <h1 class="text"><?=$vse.$text?></h1>
</div>

<div style="padding-left: 30px; padding-top: 20px;">
    <? $letter = false; $i = 0; $column = 1; $set_delim = false; $delim = (count($this->marks) - count($this->marks) % 4) / 4;?>
    <table class="treba-auto-catalog">
        <tr>
            <td>
                <? foreach ($this->marks as $mark): ?>
                <? if ($i % $delim == 0 && $i > 0 && $column < 4) {
                    $set_delim = true;
                    $column++;
                } ?>
                <? //detect new first character of string ?>
                <? if (mb_substr($mark['name'], 0, 1, 'UTF-8') != $letter) {
                    $letter = mb_substr($mark['name'], 0, 1, 'UTF-8');
                    if ($i != 0) print '</ul>';
                    if ($set_delim) {
                        print "</td><td>";
                        $set_delim = false;
                    }
                    print "<ul><li class='letter-bold'><b>$letter</b>";
                    if($mark["count"]>0){
                        print '<a href="/catalog/' . $category_url . $mark["name"] . '">' . $mark["name"] . '</a><span> (' . $mark["count"] . ')</span>';
                    }
                    else{
                        print '<span>' . $mark["name"] . '</span><span> (' . $mark["count"] . ')</span>';
                    }
                    $i++;
                    continue;
                } ?>
                <li>
                   <?
                     if($mark["count"]>0){
                        print '<a href="/catalog/' . $category_url . $mark["name"] . '">' . $mark["name"] . '</a><span> (' . $mark["count"] . ')</span>';
                    }
                    else{
                        print '<span>' . $mark["name"] . '</span><span> (' . $mark["count"] . ')</span>';
                    }?>
                </li>
                <? $i++; ?>
                <? endforeach; ?>
                </ul>
            </td>
        </tr>
    </table>
</div>
